<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
function func_call_headers() {
	header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
	header("Last-Modified: " . gmdate('D, d M Y H:i:s') . " GMT");
	header("Cache-Control: no-cache, must-revalidate");
	header("Pragma: no-cache");
	header("Content-type: text/xml; charset=UTF8");
}

function func_call_close() {
	exit();
}

function func_call_output($content, $direct = true, $root_tag = 'result') {
	$output_str = '';
	
	$output_str .= '<?xml version="1.0" encoding="utf-8"?>' . "\n";
	$output_str .= '<' . $root_tag . '>' . $content . '</' . $root_tag . '>';
	
	if( $direct == true ) {
		echo $output_str;
	} else {
		return $output_str;
	}
}

// cmd attribute
//		n		name		cmd
//		t		target		target
//		p		property
//		c		call		this.xxx/function
//<cmd n="assign" t="aaa" p="innerHTML" c="this.debug">aaaa</cmd>
function func_call_cmd($data, $name = '', $target = '', $property = '', $call = '') {
	$str = '';
	$str .= '<cmd';
	if( $name != '' ) {
		$str .= ' n="' . $name . '"';
	}
	if( $target != '' ) {
		$str .= ' t="' . $target . '"';
	}
	if( $property != '' ) {
		$str .= ' p="' . $property . '"';
	}
	if( $call != '' ) {
		$str .= ' c="' . $call . '"';
	}
	$str .= '>';
	$str .= '<![CDATA[' . $data . ']]>';
	$str .= '</cmd>';
	
	return $str;
}

//
function func_call_checkxc() {
	if( isset($_REQUEST['xc']) && isset($_REQUEST['xcr']) ) {
		return true;
	}
	
	return false;
}

function func_call_getpost() {
	
}

function func_call_checkform() {
	$form_values = array();
	if( isset($_POST['xcargs']) && sizeof($_POST['xcargs']) == 2 && $_POST['xcargs']['0'] == 'form' ) {
		return true;
	}
	
	return false;
}

function func_call_getformvalues() {
	$form_values = array();
	if( isset($_POST['xcargs']) && sizeof($_POST['xcargs']) == 2 && $_POST['xcargs']['0'] == 'form' ) {
		$value = $_POST['xcargs']['1'];
		parse_str($value, $form_values);
	}
	
	return $form_values;
}

//
function func_call_call($method, $params, $url) {
	
}
//
?>